home *** CD-ROM | disk | FTP | other *** search
- // ********************** File: prog3.C ************************
- // A program which demonstrates diverse interpolation algorithms
- // inside class BSpline and class ParametricBSpline
- #include <BSpline.h>
- #include <ParametricBSpline.h>
- #include <splineOutput.h>
-
- int main()
- {
- Vec(real) x(7), f(7); // the discrete data to be interpolated
- for (int i = 1; i <= 7; i++) { x(i)=0.6*i+0.6; f(i)=x(i)*x(i); }
-
- // first: Create knot vector, spline space and call BSpline::interpolate
- // (interpolation type as given by the spline space)
- KnotVec knots(5);
- knots.fill(1,5); knots.regulate(4); // 1 1 1 1 2 3 4 5 5 5 5
- SplineSpace space(knots,4);
- BSpline bs1;
- bs1.redim(space);
- bs1.interpolation(x,f);
- s_o << "Calling function 'interpolation' directly:\n";
- real y;
- for (i = 1; i <= 10; i++)
- { y = 1.2 + (i-1)*0.1; s_o << oform("%3.1f %4.2f\n",y,bs1(y)); }
- s_o << '\n';
-
- // second: invoke cubicInterpolation and linearInterpolation directly,
- // knot vectors and spline spaces are automatically computed
- BSpline bs2,bs3;
- s_o << "Cubic interpolation with natural boundary condition.\n\n";
- bs2.cubicInterpolation(x,f,"Natural");
- s_o << "Linear interpolation.\n\n";
- bs3.linearInterpolation(x,f);
-
- // third: the spline function is treated as a parametric curve
- Mat(real) data(7,2); // parametric curve data (x_i,f_i), i=1,..,7
- for (i = 1; i <= 7; i++) { data(i,1)=x(i); data(i,2)=f(i); }
-
- ParametricBSpline pbs;
- s_o << "Parametric cubic interpolation.\n";
- pbs.cubicInterpolation(data,"Free","Centripetal");
-
- createPlotmtvFile(pbs,1,"FILE=spline.mtv"); // plotmtv format to file
- return 0;
- }
-